package com.unohacha.qqj.fzdr.main;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.ui.activity.SySPushActivity;
import com.unohacha.qqj.fzdr.ui.activity.SysMessageActivity;
import com.unohacha.qqj.fzdr.view.DragPointView;
import com.unohacha.qqj.mylibrary.base.BaseFragment;

import butterknife.BindView;
import io.rong.imkit.fragment.ConversationListFragment;
import io.rong.imlib.model.Conversation;

/**
 * 消息碎片
 */
public class MessageFragment extends BaseFragment {
    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.common_right_text)
    TextView commonRightText;
    @BindView(R.id.system_out_tv)
    TextView systemOutTv;
    @BindView(R.id.new_out_number)
    DragPointView newOutNumber;
    @BindView(R.id.system_out_ll)
    LinearLayout systemOutLl;
    @BindView(R.id.system_out_rl)
    RelativeLayout systemOutRl;
    @BindView(R.id.system_msg_tv)
    TextView systemMsgTv;
    @BindView(R.id.new_msg_number)
    DragPointView newMsgNumber;
    @BindView(R.id.system_msg_ll)
    LinearLayout systemMsgLl;
    @BindView(R.id.system_msg_rl)
    RelativeLayout systemMsgRl;


    @Override
    protected void initBundle(Bundle arguments) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_message_layout;
    }

    @Override
    protected void initView(View rootView) {
        commonBack.setVisibility(View.INVISIBLE);
        commonTitle.setText("我的消息");
        commonRightImage.setVisibility(View.INVISIBLE);

    }

    @Override
    protected void initData() {
        newMsgNumber.setText("2");
        newOutNumber.setText("5");
        systemOutRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getContext(), SySPushActivity.class));
            }
        });
        systemMsgRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getContext(), SysMessageActivity.class));
            }
        });
        //创建事务
        FragmentTransaction ft = getChildFragmentManager().beginTransaction();
        //操作指令
        ft.add(R.id.fl_content,getConversationListFragment());
        //提交事务
        ft.commit();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }


    public ConversationListFragment getConversationListFragment(){
        ConversationListFragment listFragment = new ConversationListFragment();

        Uri uri = Uri.parse("rong://" + getActivity().getApplicationInfo().packageName).buildUpon()

                .appendPath("conversationList")

                .appendQueryParameter(Conversation.ConversationType.PRIVATE.getName(), "false")//设置私聊会话是否聚合显示

                .appendQueryParameter(Conversation.ConversationType.GROUP.getName(), "true")

                .appendQueryParameter(Conversation.ConversationType.DISCUSSION.getName(), "true")//设置私聊会话是否聚合显示

                .appendQueryParameter(Conversation.ConversationType.SYSTEM.getName(), "true")//设置私聊会是否聚合显示

                .build();

        listFragment.setUri(uri);

        return listFragment;
    }
}
